package com.zhuiyun.project.api.recording.service.Impl;

import com.zhuiyun.project.api.recording.mapper.TransactionHistoryMapper;
import com.zhuiyun.project.api.recording.model.TransactionHistoryModel;
import com.zhuiyun.project.api.recording.service.TransactionHistoryService;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.UserUtils;
import com.zhuiyun.project.util.pageUtil.MybatisPageHelper;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import com.zhuiyun.project.util.pageUtil.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName TransactionHistoryServiceImpl
 * @Description TODO
 * @Author 李中博
 * @Date 2024/9/24 20:37
 **/
@Service
public class TransactionHistoryServiceImpl implements TransactionHistoryService {
    @Autowired
    private TransactionHistoryMapper transactionHistoryMapper;
    @Override
    public CommonResult getTransactionHistoryByPage(String userName, PageRequest pageRequest) {
        // 设置分页
        MybatisPageHelper.startPage(pageRequest);
        PageResult pageResult = MybatisPageHelper.getPageResult(transactionHistoryMapper.selectTransactionHistoryAndUser(userName));
        return CommonResult.ok(pageResult);
    }

    @Override
    public CommonResult getTransactionHistoryById(Integer productId) {
        String phone = UserUtils.getUser().getPhone();
        int count = transactionHistoryMapper.getTransactionHistoryById(phone,productId);
        return CommonResult.ok(count);
    }
    /**
     * 查询出中奖且不免费并且有人付费的项目进行分账
     * @return
     */
    @Override
    public List<TransactionHistoryModel> getSubmitRecordByCountAndStatusAndFlag(String lastLotteryNo) {
        return transactionHistoryMapper.getTransactionByProductIdAndLotteryNo(lastLotteryNo);
    }

    @Override
    public void updateSeparateFlag(Integer id,String state) {
        transactionHistoryMapper.updateSeparateFlag(id,state);
    }
}
